<%--
  Created by IntelliJ IDEA.
  User: 27933
  Date: 2021/10/14
  Time: 10:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>$Title$</title>
    <script src="static/js/jquery.js"></script>
    <script>
        var ch;

        function ajax() {
            ch = new XMLHttpRequest();
            // ch.onreadystatechange = function () {
            //   alert("dhjaddddddddd");
            // };
            ch.onreadystatechange = say;
            // ch.open("GET", "/helloController?name=张");
            ch.open("POST", "/helloController?name=张")
            ch.send();
            // ch.send("name"+name);


        }

        function say() {
            if (ch.readyState && ch.status) {
                document.getElementById("d").innerText = ch.responseText;
            }
        }

        // $(function () {
        //     $("#sa").click(function () {
        //         $.get("/hello2Controller",
        //             {name: "李云鹏", sex: "女"},
        //             function () {
        //                 alert("成功");
        //             }
        //         )
        //     });
        // });


        $(function () {
            $("#fo").submit(function (e) {
                // e.preventDefault();
                $.post("/postController",
                    $(this).serialize(), function (data) {
                      // var jsonObj  =JSON.parse(data);
                        $("#fo").html("编号："+data.id+",姓名："+data.name);
                    }, "JSON"
                );
            });

        });
    </script>
</head>
<body>
<button onclick="ajax()" id="sa">点这里</button>
<div id="d"></div>
<form action="" id="fo">
    <input type="text" name="id">
    <input type="text" name="name">
    <input type="submit" value="提交">
</form>
</body>
</html>
